//
//  TradeRecordTableViewCell.m
//  ZYZB
//
//  Created by ENERGY on 2018/7/9.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "HoldingTradeRecordTableViewCell.h"

@interface HoldingTradeRecordTableViewCell()
@property (nonatomic, strong)UILabel * titleLab;//标题名
@property (nonatomic, strong)UILabel * profitContentLab;//利息
@property (nonatomic, strong)UILabel * daysLab;//天数
@property (nonatomic, strong)UILabel * projectNameLab;//标的名
@property (nonatomic, strong)UIButton * interestBtn;//查看返息
@property (nonatomic, strong)UIButton * contractBtn;//查看合同
@property (nonatomic, strong)NSString * bidID;//标的ID
@end
@implementation HoldingTradeRecordTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        __weak typeof (self)weakSelf = self;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.titleLab];
        [self.contentView addSubview:self.profitContentLab];
        [self.contentView addSubview:self.daysLab];
        [self.contentView addSubview:self.projectNameLab];
        [self.contentView addSubview:self.interestBtn];
        [self.contentView addSubview:self.contractBtn];
        UIView * lineViw = [[UIView alloc] init];
        lineViw.backgroundColor = getColor(grayColor);
        [self.contentView addSubview:lineViw];
        [lineViw mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(weakSelf.contentView.mas_bottom);
            make.height.mas_offset(1/WIDTH_6_SCALE);
            make.left.equalTo(weakSelf.contentView.mas_left).mas_offset(18/WIDTH_6_SCALE);
            make.right.equalTo(weakSelf.contentView.mas_right).mas_offset(-18/WIDTH_6_SCALE);
        }];
        [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView.mas_left).mas_offset(18/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.contentView.mas_top).mas_offset(22/WIDTH_6_SCALE);
            make.height.mas_offset(10/WIDTH_6_SCALE);
        }];
        [self.profitContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.titleLab);
            make.top.equalTo(weakSelf.titleLab.mas_bottom).mas_offset(15/WIDTH_6_SCALE);
        }];
        [self.daysLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.titleLab);
            make.top.equalTo(weakSelf.profitContentLab.mas_bottom).mas_offset(12/WIDTH_6_SCALE);
            make.bottom.equalTo(weakSelf.contentView.mas_bottom).mas_offset(-17/WIDTH_6_SCALE);
        }];
        [self.projectNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.height.equalTo(weakSelf.daysLab);
            make.right.equalTo(weakSelf.contentView.mas_right).mas_offset(-18/WIDTH_6_SCALE);
//            make.height.mas_offset(12/WIDTH_6_SCALE);
        }];
        [self.interestBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.titleLab);
            make.width.mas_offset(64/WIDTH_6_SCALE);
            make.height.mas_offset(28/WIDTH_6_SCALE);
            make.right.equalTo(weakSelf.contractBtn.mas_left).mas_offset(-22/WIDTH_6_SCALE);
        }];
        [self.contractBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.height.width.equalTo(weakSelf.interestBtn);
            make.right.equalTo(weakSelf.contentView.mas_right).mas_offset(-18/WIDTH_6_SCALE);
        }];
    }return self;
}
- (UILabel *)titleLab{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.font = DEF_FontSize_10;
        _titleLab.textColor = [UIColor blackColor];
        _titleLab.textAlignment = NSTextAlignmentLeft;
        _titleLab.text = @"预期收益(元)";
    }return _titleLab;
}
- (UILabel *)profitContentLab{
    if (!_profitContentLab) {
        _profitContentLab = [[UILabel alloc] init];
        _profitContentLab.font = [UIFont systemFontOfSize:24.0];
        _profitContentLab.textColor = [UIColor blackColor];
        _profitContentLab.textAlignment = NSTextAlignmentLeft;
        _profitContentLab.text = @"13,660.73";
    }return _profitContentLab;
}
- (UILabel *)daysLab{
    if (!_daysLab) {
        _daysLab = [[UILabel alloc] init];
        _daysLab.font = [UIFont systemFontOfSize:12.0];
        _daysLab.textColor = [UIColor blackColor];
        _daysLab.textAlignment = NSTextAlignmentLeft;
        _daysLab.text = @"距离到期还有365天";
    }return _daysLab;
}
- (UILabel *)projectNameLab{
    if (!_projectNameLab) {
        _projectNameLab = [[UILabel alloc] init];
        _projectNameLab.font = [UIFont systemFontOfSize:12.0];
        _projectNameLab.textColor = getColor(@"bdbdbd");
        _projectNameLab.textAlignment = NSTextAlignmentRight;
        _projectNameLab.text = @"【家家泰365天J16062141】";
    }return _projectNameLab;
}
-  (UIButton *)interestBtn{
    if (!_interestBtn) {
        _interestBtn = [[UIButton alloc] init];
        _interestBtn.titleLabel.font = DEF_FontSize_10;
        [_interestBtn setTitle:@"查看返息" forState:UIControlStateNormal];
        [_interestBtn setBackgroundColor:[UIColor clearColor]];
        [_interestBtn setTitleColor:getColor(@"ff8819") forState:UIControlStateNormal];
        [_interestBtn addTarget:self action:@selector(interestBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _interestBtn.layer.borderColor = getColor(@"ff8819").CGColor;
        _interestBtn.layer.borderWidth = 1;
        _interestBtn.layer.cornerRadius = 6;
        _interestBtn.layer.masksToBounds = YES;
    }
    return _interestBtn;
}
-  (UIButton *)contractBtn{
    if (!_contractBtn) {
        _contractBtn = [[UIButton alloc] init];
        _contractBtn.titleLabel.font = DEF_FontSize_10;
        [_contractBtn setTitle:@"查看合同" forState:UIControlStateNormal];
        [_contractBtn setBackgroundColor:[UIColor clearColor]];
        [_contractBtn setTitleColor:getColor(@"3675bd") forState:UIControlStateNormal];
        _contractBtn.layer.borderColor = getColor(@"3675bd").CGColor;
        _contractBtn.layer.borderWidth = 1;
        _contractBtn.layer.cornerRadius = 6;
        _contractBtn.layer.masksToBounds = YES;
        [_contractBtn addTarget:self action:@selector(contractBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _contractBtn;
}
- (void)contractBtnClick:(UIButton *)sender{
    if (self.contractBtnBlock) {
        self.contractBtnBlock();
    }
}
- (void)interestBtnClick:(UIButton *)sender{
    if (self.interestBtnBlock) {
        self.interestBtnBlock();
    }
}
- (void)setModel:(NSDictionary *)model{
    _model = model;
    self.profitContentLab.text = model[@"earnings"];
    self.daysLab.text = [NSString stringWithFormat:@"距离到期还有%@天", model[@"day"]];
    self.projectNameLab.text = [NSString stringWithFormat:@"【%@】", model[@"productName"]];
    self.bidID = model[@"bid"];
}
@end
